package com.jsyl.lwbk.web.controller.fusion;

import com.jsyl.lwbk.business.domain.education.ChildCourse;
import com.jsyl.lwbk.business.dto.ChildCourseDTO;
import com.jsyl.lwbk.business.dto.ReadingComprehensionScoreDTO;
import com.jsyl.lwbk.business.dto.SaveReadingScoreDTO;
import com.jsyl.lwbk.business.service.CourseChildScoreService;
import com.jsyl.lwbk.business.service.PrepareClassService;
import com.jsyl.lwbk.common.core.controller.BaseController;
import com.jsyl.lwbk.common.core.domain.AjaxResult;
import com.jsyl.lwbk.common.core.page.TableDataInfo;
import com.jsyl.lwbk.framework.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社交准备课
 */
@Controller
@RequestMapping("/socialize")
public class SocializeController extends BaseController {

    private String prefix = "fusion";

    @Autowired
    PrepareClassService prepareClassService;

    @Autowired
    CourseChildScoreService courseChildScoreService;

    /**
     * 课程列表主页
     *
     * @param mmap
     * @return
     */
    @GetMapping()
    public String child(ModelMap mmap) {
        mmap.put("teacherId", ShiroUtils.getUserId());
        return prefix + "/socializeScheduleList";
    }

    /**
     * 课程列表主页分页数据
     *
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findList(ChildCourseDTO dto) {
        startPage();
        List<ChildCourse> list = prepareClassService.listSocialize(dto, ShiroUtils.getSysUser());
        return getDataTable(list);
    }

    /**
     * 确认月计划
     *
     * @return
     */
    @PostMapping("/savePlan")
    @ResponseBody
    public AjaxResult savePlan(@RequestParam("classId") Long classId,
                               @RequestParam("classTimes") Integer classTimes,
                               @RequestParam("classPlanId") Long classPlanId) {
        this.prepareClassService.saveFusionPlan(classId,classTimes, classPlanId);
        return success();
    }


    /**
     * 取消备课
     *
     * @return
     */
    @PostMapping("/cancelPlan")
    @ResponseBody
    public AjaxResult cancelPlan(@RequestParam("id") Long id) {
        this.prepareClassService.cancelPlan(id);
        return success();
    }

    /**
     * 页面跳转-成绩录入
     *
     * @param mmap
     * @return
     */
    @GetMapping("/childScoreList/{childCourseId}/{scoreFlag}")
    public String list(@PathVariable("childCourseId") Long childCourseId,@PathVariable("scoreFlag") Integer scoreFlag, ModelMap mmap) {
        mmap.put("childCourseId", childCourseId);
        mmap.put("scoreFlag", scoreFlag);
        return prefix + "/childScoreList";
    }

    /**
     * 阅读理解学员成绩
     *
     * @return
     */
    @GetMapping("/listChildScore")
    @ResponseBody
    public AjaxResult listHistoryScore(@RequestParam("childCourseId") Long childCourseId) {
        List<ReadingComprehensionScoreDTO> list = courseChildScoreService.listChildScore(childCourseId);
        return AjaxResult.success(list);
    }

    /**
     * 保存成绩
     *
     * @param dto
     * @return
     */
    @PostMapping("/saveScore")
    @ResponseBody
    public AjaxResult saveScore(@RequestBody SaveReadingScoreDTO dto) {
        dto.setUpdateUser(ShiroUtils.getLoginName());
        this.courseChildScoreService.saveReadingComprehensionScore(dto);
        return success();
    }


}
